if (!window.mask) window.mask = (function ($) {
    var mask, splash, W, H;

    function createMask () {
        if (!mask) {
            mask = $('<div id="salon-mask"/>').css ({
                'background-color': '#000',
                opacity:0,
                position: 'fixed',
                top: 0,
                left: 0,
                'z-index' : 666,
                width: $(window).width (),
                height : $(window).height ()
            }).on ('click', function (event) {event.stopPropagation();});
            W = mask.width ();
            H = mask.height ();
        }
        return mask;
    }

    return {
        show : function () {
            createMask ();
            $(function () {
                mask.appendTo ($(document.body));
            });
            var a = 0, args = arguments;
            mask.show ();
            var handler = setInterval (function () {
                if (a < .5) {
                    a += .05;
                    mask.css ({opacity: a});
                } else {
                    clearInterval (handler);
                    call (mask, args);
                }
            }, 20);
        },
        hide : function () {
            mask.empty ();
            var a = .5, args = arguments, handler = setInterval (function () {
                if (a > 0) {
                    a -= .05;
                    mask.css ({opacity: a});
                } else {
                    mask.hide ();
                    clearInterval(handler);
                    call (mask, args);
                }
            }, 20);
        },
        size : function () {
            return {width: mask.width (), height: mask.height ()}
        },
        showSplash : function (target) {
            this.show (function () {
                splash = $('<div/>').append ($(target)).css ('position', 'fixed').appendTo (mask);
                var w = splash.width (), h = splash.height (),
                    x = (W - w) / 2, y = (H - h) / 2;
                splash.css ({left:x,top:y}).show ();
            });
        }
    };
})(jQuery);